import {
  LocalizationContext,
  MinimalButton,
  Position,
  ThemeContext,
  Tooltip,
} from "../../core";

import DarkIcon from "./DarkIcon";
import LightIcon from "./LightIcon";
import { FC, useContext } from "react";

interface SwitchThemeButtonProps {
  onClick(): void;
}

const TOOLTIP_OFFSET = { left: 0, top: 8 };

const SwitchThemeButton: FC<SwitchThemeButtonProps> = ({ onClick }) => {
  const theme = useContext(ThemeContext);
  const l10n = useContext(LocalizationContext);
  const isDarkTheme = theme.currentTheme === "dark";

  const label =
    l10n && l10n.theme
      ? isDarkTheme
        ? l10n.theme.switchLightTheme
        : l10n.theme.switchDarkTheme
      : isDarkTheme
      ? "Switch to the light theme"
      : "Switch to the dark theme";

  return (
    <Tooltip
      position={Position.BottomCenter}
      target={
        <MinimalButton onClick={onClick}>
          {isDarkTheme ? <LightIcon /> : <DarkIcon />}
        </MinimalButton>
      }
      content={() => label}
      offset={TOOLTIP_OFFSET}
    />
  );
};

export default SwitchThemeButton;
